<!-- 新增编辑查看进场函 -->
<template>
        <div class="s_body">
                <h4>进场函基本信息：</h4>
                <el-form ref="ruleForm"  :inline="true" :model="params" class="demo-form-inline" :rules="rules">
                        <div>
                                <el-form-item label="项目名称：" label-width="180px" prop="projectId">
                                       <el-input v-model="params.projectId" disabled style="width:217px;display:none;" placeholder="请选择项目名称"></el-input>
                                       <el-input v-model="params.projectName" disabled style="width:217px;" placeholder="请选择项目名称"></el-input>
                                       <el-button type="primary" style="margin-left:-3.5px;" @click="openCooproject" :disabled="type=='look'">选择</el-button>
                                </el-form-item>
                                <el-form-item label="楼盘名称：" label-width="180px" prop="devId">
                                    <el-select v-model="params.devId" :disabled="devs.length==1 || type== 'look' " @change="choseDevname">
                                        <el-option v-for="(item,index) in devs" :label="item.devName" :value="item.devId" :key="index"></el-option>
                                    </el-select>
                                </el-form-item>
                        </div>
                        <div>
                                <el-form-item label="合作开始日期：" label-width="180px" prop="contractBeginDate">
                                        <el-date-picker
                                             v-model="params.contractBeginDate"
                                             type="date"
                                             value-format="yyyy-MM-dd"
                                             placeholder="请选择合作开始日期"  :disabled="type=='look'">
                                     </el-date-picker>
                                </el-form-item>
                                <el-form-item label="合作结束日期：" label-width="180px" prop="contractEndDate">
                                        <el-date-picker
                                             v-model="params.contractEndDate"
                                             type="date"
                                             value-format="yyyy-MM-dd"
                                             placeholder="请选择合作结束日期"  :disabled="type=='look'">
                                     </el-date-picker>
                                </el-form-item>
                        </div>
                        <div>
                                <el-form-item label="进场日期：" label-width="180px" prop="approachDate">
                                        <el-date-picker
                                             v-model="params.approachDate"
                                             type="date"
                                             value-format="yyyy-MM-dd"
                                             placeholder="请选择进场日期"  :disabled="type=='look'">
                                     </el-date-picker>
                                </el-form-item>
                                <el-form-item label="委托物业：" label-width="180px" prop="entrustEstates">
                                        <el-input v-model="params.entrustEstates" placeholder="请输入" style="width:524px;" :disabled="type=='look'" maxlength="100"></el-input>
                                </el-form-item>
                        </div>
                </el-form>
                <h4>代理佣金结算标准：</h4>
                <el-button type="primary" style="margin-bottom:25px;" @click="addProduct" v-if="type != 'look' ">新增</el-button>
                <el-table :data="tableData" v-loading="loading" border stripe>
                        <el-table-column type="index" label="序号" align="center" width="55"></el-table-column>
                        <el-table-column prop="name" label="产品名称" align="center"></el-table-column>
                        <el-table-column prop="standard" label="服务费结算标准(元/套)" align="center"></el-table-column>
                        <el-table-column prop="node" label="服务费结算节点" align="center"></el-table-column>
                        <el-table-column  label="操作" align="center"  v-if="type != 'look' ">
                                <template slot-scope="scope">
                                        <el-button type="text" size="small" @click="editBrokerage(scope.row,scope.$index)">编辑</el-button>
                                        <el-button type="text" size="small" @click="delItem('txt',scope.$index,scope.row)">删除</el-button>
                                </template>
                        </el-table-column>
                </el-table>
                <h4 class="commonclass">关键条款概述：</h4>
                <el-input type="textarea" :rows="6" v-model="params.termsDetail" placeholder="请输入关键条款概述" :disabled="type=='look'" maxlength="500"></el-input>
                <div class="uploadBox" >
                        <div style="display:flex;">
                                <p>进场函附件：</p>
                                <uploadAll type="text" ref="uploadRef"  @selectedFile="selectedFile" :accept="accept" :multiple="true" class="disUpload" :fileList="fileList" v-if="type != 'look' "></uploadAll>
                        </div>
                        <p style="color:#ccc;font-size:14px;margin-left:95px;" v-if="type != 'look' ">支持扩展名：.doc .docx .pdf .png .jpg</p>
                </div>
                <el-table :data="uploadData" border stripe>
                        <el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
                        <el-table-column label="文件名称" prop="fileName" align="center"></el-table-column>
                        <el-table-column label="上传文件名" prop="fileUploadName" align="center"></el-table-column>
                        <el-table-column label="创建人" prop="createUserName" align="center"></el-table-column>
                        <el-table-column label="上传时间" prop="createTimeStr" align="center"></el-table-column>
                        <el-table-column label="操作"  align="center">
                                <template slot-scope="scope">
                                        <el-button type="text" size="small" @click="modifyName(scope.row.fileName,scope.$index)" v-if="type != 'look' ">修改文件名</el-button>
                                        <el-button type="text" size="small"  v-if=" 
                                            scope.row.fileUploadName.substring(scope.row.fileUploadName.lastIndexOf('.')+1,scope.row.fileUploadName.length) == 'doc' ||
                                            scope.row.fileUploadName.substring(scope.row.fileUploadName.lastIndexOf('.')+1,scope.row.fileUploadName.length) == 'docx'
                                        "
                                        @click="downDoc(scope.row.fileAddress,scope.row.fileUploadName)">下载</el-button>
                                        <el-button type="text" size="small" v-else-if=" 
                                            scope.row.fileUploadName.substring(scope.row.fileUploadName.lastIndexOf('.')+1,scope.row.fileUploadName.length) == 'pdf'
                                        "
                                        @click="previewFile(scope.row.fileAddress,'pdf')">下载</el-button>

                                        <el-button type="text" size="small" v-else @click="downPic(scope.row.fileAddress,scope.row.fileUploadName,scope.row.createTimeStr)">下载</el-button>

                                        <el-button type="text" size="small" v-if=" 
                                            scope.row.fileUploadName.substring(scope.row.fileUploadName.lastIndexOf('.')+1,scope.row.fileUploadName.length) == 'doc' ||
                                            scope.row.fileUploadName.substring(scope.row.fileUploadName.lastIndexOf('.')+1,scope.row.fileUploadName.length) == 'docx'
                                        "
                                        :disabled="true" >预览</el-button>
                                        <el-button type="text" size="small" v-else-if=" 
                                            scope.row.fileUploadName.substring(scope.row.fileUploadName.lastIndexOf('.')+1,scope.row.fileUploadName.length) == 'pdf'
                                        "
                                         @click="previewFile(scope.row.fileAddress,'pdf')">预览</el-button>
                                         <el-button type="text" size="small" v-else
                                         @click="previewFile(scope.row.fileAddress,'jpg')">预览</el-button>

                                        <el-button type="text" size="small" @click="delItem('mod',scope.$index,scope.row)" v-if="type != 'look' ">删除</el-button>
                                </template>
                        </el-table-column>
                </el-table>
                <div v-if=" type == 'look' ">
                    <p>审核记录</p>
                    <table class="tabs">
                        <tr>
                            <td>操作</td>
                            <td>操作人</td>
                            <td>角色</td>
                            <td>时间</td>
                            <td>审批意见</td>
                        </tr>
                        <tr v-for="item in logList">
                            <td>{{item.actionName | initActionName}}</td>
                            <td>{{item.participantName}}</td>
                            <td>{{item.displayName}}</td>
                            <td>{{item.receiveTime}}</td>
                            <td>{{item.itemComment}}</td>
                        </tr>
                    </table>
                </div>
                <div style="text-align:center;margin-top:30px;" v-if="type != 'look' ">
                        <el-button type="primary" @click="faqishenpi">发起审批</el-button>
                        <el-button type="primary" @click="saveProduct">保存</el-button>
                        <el-button type="primary" @click="cancelSaveProduct">取消</el-button>
                </div>
                <el-dialog title="" :visible.sync="newProductVisible" width="70%" >
                        <el-form ref="productFrom" :inline="true" :model="Productparams" class="demo-form-inline" label-width="180px" style="margin-top:50px;" :rules="rules">
                                <div>
                                        <el-form-item label="产品名称：" prop="name">
                                                <el-input v-model="Productparams.name" placeholder="请输入产品名称" maxlength="20"></el-input>
                                        </el-form-item>
                                        <el-form-item label="服务费结算标准(元/套)：" prop="standard">
                                                <el-input v-model="Productparams.standard" placeholder="请输入服务费结算标准"></el-input>
                                        </el-form-item>
                                </div>
                                <div  class="especially">
                                        <el-form-item label="服务费用结算节点：" prop="node">
                                                <el-input type="textarea" :rows="3" v-model="Productparams.node" placeholder="请输入服务费用结算节点信息" maxlength="100"></el-input>
                                        </el-form-item>
                                </div>
                                <div style="margin-left:260px;">
                                        <el-button type="primary" @click="saveProduce">保存</el-button>
                                        <el-button type="primary" @click="cancel">取消</el-button>
                                </div>
                        </el-form>
                </el-dialog>
                <el-dialog title="编辑文件名" :visible.sync="modifydialogVisible" width="30%" >
                        <el-input  placeholder="请输入文件名"  v-model.trim="textmodify" maxlength="30"></el-input>
                        <div class="btns" style="margin-top:15px;text-align:center;">
                                <el-button type="primary" @click="modifySave">保存</el-button>
                                <el-button type="primary" @click="modifycancel">取消</el-button>
                        </div>
                </el-dialog>
                <el-dialog :visible.sync="imgLookdialogVisible">
                    <img width="100%" :src="dialogImageUrl" alt="" v-if="fileType=='jpg'">
                    <iframe :src="dialogImageUrl" style="width:100%;height:600px;" v-if="fileType=='pdf'"></iframe>
                </el-dialog>
                <createCoop
                        :choseCooprojectVisible="choseCooprojectVisible"
                        @closechosecooproject="closeChoseCooproject"
                        :choseCooprojectData="choseCooprojectData"
                        :pageNum="choseCooprojectPageNum"
                        :pageSize="choseCooprojectPageSize"
                        @handleSizeChange="handleSizeChange1"
                        @handleCurrentChange="handleCurrentChange1"
                        @getCooprojectItem="getCooprojectItem"
                        :choseCooprojectRadio="choseCooprojectRadio"
                        @assignmentCooproject="assignmentCooproject"
                        @queryProject="queryProject"
                        @creatproject="creatproject"
                        @projectCity="projectCity"
                        :provinces="provinces"
                        :citys="citys"
                        :developers="developers"
                        @insertProject="insertProject"
                        :total="choseCooprojectTotal"
                />
        </div>
</template>

<script>
import api from '@/api/apiPath'
import uploadAll from "../../common/Upload"
import createCoop from "../common/createCooproject"
export default {
        data(){
                return {
                        fileType:"",
                        imgLookdialogVisible:false,
                        dialogImageUrl:"",
                        fileList:[],
                        accept: '.doc,.docx,.pdf,.jpg,.png,.jpeg,.PNG,.gif',
                        devs:[],//新增楼盘展示
                        selectQueryProjectName:"",
                        logList:[],//审核记录列表
                        maxMoney:sessionStorage.getItem("maxMoney"),
                        type:this.$route.query.type,//进场函编辑或者查看
                        id:this.$route.query.id,//进场函id
                        choseCooprojectVisible:false,//选择合作项目的boolean
                        choseCooprojectPageNum:1,//选择合作项目的分页
                        choseCooprojectPageSize:10,//选择合作项目的分页
                        choseCooprojectRadio:-1,//选择合作项目的单选按钮
                        choseCooprojectSelected:{},//选择合作项目的单选的数据
                        nameproject:"",//选择合作项目的项目名称仅做展示用
                        choseCooprojectTotal:0,//选择合作项目的总条数
                        choseCooprojectData:[],//选择合作项目的数据
                        provinces:[],//新建项目的省份
                        citys:[],//新建项目的城市
                        developers:[],//新建项目的开发商
                        tableData:[],
                        editTableIds:[],
                        loading:false,
                        uploadData:[],
                        editUploadDataIds:[],
                        newProductVisible:false,//新增产品信息
                        isaddP:0,//是否是添加代理佣金
                        editPindex:"",//编辑代理佣金的index
                        editUindex:"",//编辑进场函附件的index
                        modifydialogVisible:false,//编辑上传文件名
                        modifyindex:"",//编辑上传文件名index
                        textmodify:"",//编辑文件名的字段
                        params:{
                                devId:"",
                                devName:"",
                                contractCode:this.$route.query.contractCode,
                                projectId:"",//项目id
                                projectName:"",//项目名称
                                contractBeginDate:"",//合作开始日期
                                contractEndDate:"",//合作结束日期
                                approachDate:"",//进场日期
                                entrustEstates:"",//委托物业
                                termsDetail:"",//关键条款
                                createUserid:JSON.parse(sessionStorage.getItem("cmsUser")).userId,//创建人
                                createUserName:JSON.parse(sessionStorage.getItem("cmsUser")).name,//创建人
                                updateUserid:JSON.parse(sessionStorage.getItem("cmsUser")).userId,//更新人
                                updateUserName:JSON.parse(sessionStorage.getItem("cmsUser")).name//更新人
                        },
                        Productparams:{
                                name:"",
                                standard:"",
                                node:""
                        },
                        rules:{
                                projectId:[{
                                        required:true,
                                        validator: (rule, value, callback) => {
                                            if(value==""){
                                                    return callback(new Error('请选择项目'));
                                            }
                                            callback();
                                        }
                                }],
                                contractBeginDate:[{required: true, message: '请选择合作开始日期', trigger: 'change'}],
                                contractEndDate:[{required: true, message: '请选择合作结束日期', trigger: 'change'}],
                                approachDate:[{required: true, message: '请选择进场日期', trigger: 'change'}],
                                entrustEstates:[{required: true, message: '请输入委托物业', trigger: 'blur'}],
                                name:[
                                        {required: true, message: '请输入产品名称', trigger: 'blur'}
                                ],
                                standard:[
                                        {
                                                required: true,
                                                validator: (rule, value, callback) => {
                                                    if(value==""){
                                                           return callback(new Error('请输入服务费'));
                                                    }
                                                    if(value<0){
                                                            return callback(new Error('服务费不能为负'));
                                                    }
                                                    if(value>this.maxMoney){
                                                            return callback(new Error('服务费不能大于合同上限金额'));
                                                    }
                                                    let reg = /^[0-9]\d*$/;
                                                    if (!reg.test(value)) {
                                                        return callback(new Error('请输入正确的服务费结算标准'));
                                                    }
                                                    callback();
                                                }
                                        }
                                ],
                                node:[
                                        {required: true, message: '请输入服务费用结算节点信息', trigger: 'blur'}
                                ],
                                devId:[
                                    {required: true, message: '请选择楼盘', trigger: 'change'}
                                ]
                        }
                }
        },
        filters:{
            initActionName(value){
                if(value=="Submit"){
                    return "审核通过"
                }else if(value=="Reject"){
                    return "审核拒绝"
                }else{
                    return "发起审批"
                }
            }
        },
        methods:{
                initEnterData(){
                        let id=Number(this.id)
                        this.axios.post(api.ENTERLOOK,{id:id}).then((res)=>{
                                let result=res.data.data;
                                if(res.data.code==200){
                                        this.loadDevs(result.approach.projectId);
                                        this.params.projectName=result.approach.projectName;
                                        this.params.projectId=result.approach.projectId;
                                        this.params.contractCode=result.approach.contractCode;
                                        this.params.contractBeginDate=this.getTimeString(result.approach.contractBeginDate);
                                        this.params.contractEndDate=this.getTimeString(result.approach.contractEndDate);
                                        this.params.approachDate=this.getTimeString(result.approach.approachDate);
                                        this.params.entrustEstates=result.approach.entrustEstates;
                                        this.params.devId=result.approach.devId.toString();
                                        this.params.devName=result.approach.devName;
                                        this.params.termsDetail=result.approach.termsDetail;
                                        this.tableData=result.productList;
                                        let tempfileList=[];
                                        for(var i=0;i<result.fileList.length;i++){
                                                tempfileList.push({
                                                        id:result.fileList[i].fileId,
                                                        fileType:2,
                                                        fileName:result.fileList[i].fileName,
                                                        fileUploadName:result.fileList[i].fileUploadName,
                                                        fileAddress:result.fileList[i].fileAddress,
                                                        createTime:new Date(this.getTimeString1(result.fileList[i].createTime)).getTime(),
                                                        createTimeStr:this.getTimeString1(result.fileList[i].createTime),
                                                        createUserid:JSON.parse(sessionStorage.getItem("cmsUser")).userId,//创建人
                                                        createUserName:JSON.parse(sessionStorage.getItem("cmsUser")).name//创建人
                                                })
                                                this.fileList.push(result.fileList[i].fileAddress);
                                        }
                                        this.uploadData=tempfileList;
                                        this.logList=result.logList;
                                }

                        }).catch((error)=>{
                                console.log(error);
                        })
                },
                warn(msg) {
                        this.$alert(msg, '提示', {
                                type: 'error',
                                confirmButtonText: '确定',
                                callback: action => {
                                }
                        });
                },
                openCooproject(){
                        this.choseCooprojectVisible=true;
                        this.initProject();
                },
                closeChoseCooproject(){//关闭选择合作项目的弹框
                        this.choseCooprojectVisible=false;
                        this.choseCooprojectRadio=-1;
                },
                initProject(projectName){//初始化合作项目列表
                        this.axios.post(api.INITPROJECT,{pageNum:this.choseCooprojectPageNum,pageSize:this.choseCooprojectPageSize,projectName:projectName}).then((res)=>{
                              if(res.data.code==200){
                                      this.choseCooprojectData=res.data.data.list;
                                      this.choseCooprojectTotal=res.data.data.total;
                              }
                        }).catch((error)=>{
                                console.log(error)
                        })
                },
                getCooprojectItem(row){//选择合作项目id6
                        this.choseCooprojectRadio=this.choseCooprojectData.indexOf(row);
                        this.choseCooprojectSelected=row;
                },
                assignmentCooproject(){//选择合作项目点击确定赋值给后端的参数
                        this.params.projectId=this.choseCooprojectSelected.projectId;
                        this.params.projectName=this.choseCooprojectSelected.projectName;
                        this.choseCooprojectRadio=-1;
                        this.choseCooprojectVisible=false;
                        this.params.devId="";
                        this.params.devName="";
                        this.loadDevs(this.choseCooprojectSelected.projectId)
                },
                loadDevs(projectId){
                    this.axios.post(api.LETTERDEVS,{projectId:projectId}).then((res)=>{
                        console.log(res);
                        if(res.data.code==200){
                            if(res.data.data){
                                this.devs=res.data.data;
                                if(res.data.data.length>1){
                                    this.devs.unshift({"devId":-1,"devName":"所有楼盘"})
                                }else{
                                    this.params.devId=res.data.data[0].devId;
                                    this.params.devName=res.data.data[0].devName;
                                }
                                // if(res.data.data.length !=0){
                                //     if(res.data.data.length==1){
                                //         this.params.devId=res.data.data[0].devId;
                                //         this.params.devName=res.data.data[0].devName;
                                //     }else{
                                //         this.devs.push({"devId":-1,"devName":"所有楼盘"})
                                //     }
                                // }
                            }
                        }else{
                            this.warn(res.data.msg);
                        }
                    }).catch((error)=>{
                        console.log(error);
                    })
                },
                choseDevname(val){
                    for(let i=0;i<this.devs.length;i++){
                        if(val==this.devs[i].devId){
                            this.params.devName=this.devs[i].devName
                        }
                    }
                },
                insertProject(params){
                        let newParams={};
                        newParams.projectName=params.projectName;
                        newParams.projectProvince=params.province;
                        newParams.projectCity=params.city;
                        newParams.developerId=params.developer;
                        for(var i=0;i<this.provinces.length;i++){
                                if(params.province==this.provinces[i].provinceid){
                                        newParams.projectProvinceName=this.provinces[i].province
                                }
                        }
                        for(var i=0;i<this.citys.length;i++){
                                if(params.city==this.citys[i].cityId){
                                        newParams.projectCityName=this.citys[i].city
                                }
                        }
                        for(var i=0;i<this.developers.length;i++){
                                if(params.developer==this.developers[i].id){
                                        newParams.developerName=this.developers[i].companyName
                                }
                        }
                        this.axios.post(api.INSERTPROJECT,newParams).then((res)=>{
                                if(res.data.code==200){
                                        this.initProject()
                                }
                        }).catch((error)=>{
                                console.log(error)
                        })
                },
                handleSizeChange1(val) {//选择合作项目分页
                        this.choseCooprojectPageSize = val;
                        this.initProject(this.selectQueryProjectName);
                },
                handleCurrentChange1(val) {//选择合作项目分页
                        this.choseCooprojectPageNum = val;
                        this.initProject(this.selectQueryProjectName);
                },
                queryProject(val){//查询合作项目分页
                        this.choseCooprojectPageNum = 1;
                        this.choseCooprojectPageSize = 10;
                        this.selectQueryProjectName=val;
                        this.initProject(val);
                },
                creatproject(){//项目新建的省份
                        this.axios.get(api.PROJECTPROVINCE).then((res)=>{
                                if(res.data.code==200){
                                        this.provinces=res.data.data;
                                }
                        }).catch((error)=>{
                                console.log(error)
                        })
                        this.axios.post(api.PROJECTDEVELOPER,{}).then((res)=>{
                                if(res.data.code==200){
                                        this.developers=res.data.data.list;
                                }
                        }).catch((error)=>{
                                console.log(error)
                        })
                },
                projectCity(id){
                        this.axios.get(api.PROJECTCITY+"/"+id).then((res)=>{
                                if(res.data.code==200){
                                       this.citys=res.data.data;
                                }
                        }).catch((error)=>{
                                console.log(error)
                        })
                },
                previewFile(url,type){//预览
                    this.fileType=type;
                    this.dialogImageUrl=url;
                    this.imgLookdialogVisible=true;
                },
                selectedFile(data){
                    let reader = new FileReader()
                    reader.readAsDataURL(data)
                    reader.onloadend = () => {
                        this.uploadData.push({
                            fileType:2,
                            fileName:data.name,
                            fileStatus:0,
                            fileUploadName:data.name,
                            fileAddress:reader.result,
                            createTimeStr:"",
                            createUserid:JSON.parse(sessionStorage.getItem("cmsUser")).userId,
                            createUserName:JSON.parse(sessionStorage.getItem("cmsUser")).name,
                            updateUserid:""
                        })
                    }
                },
                saveProduce(){
                        let data=JSON.parse(JSON.stringify(this.Productparams));
                        if(this.isaddP==0){
                                this.$refs['productFrom'].validate((valida)=>{
                                        if(!valida){
                                                return
                                        }
                                        this.tableData.push(data);
                                        this.newProductVisible=false;
                                        this.isaddP=0;
                                })
                        }else{
                                this.$refs['productFrom'].validate((valida)=>{
                                        if(!valida){
                                                return
                                        }
                                        this.tableData[this.editPindex]=data;
                                        this.newProductVisible=false;
                                        this.isaddP=0;

                                })
                        }

                },
                cancel(){
                        this.newProductVisible=false;
                },
                addProduct(){
                        this.Productparams.name="";
                        this.Productparams.standard="";
                        this.Productparams.node="";
                        this.newProductVisible=true;
                },
                editBrokerage(data,index){//编辑代理佣金结算标准
                        this.isaddP=1;
                        this.Productparams=data;
                        this.newProductVisible=true;
                        this.editPindex=index;
                },
                delItem(type,index,data){
                        this.$confirm("此操作将删除该条记录, 是否继续?","提示",{
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                type: 'warning'
                        }).then(()=>{
                                this.$alert("操作成功", '提示', {
                                        type: 'success ',
                                        confirmButtonText: '确定',
                                        callback: action => {
                                                if(type=="txt"){
                                                        this.tableData.splice(index,1)
                                                }else{
                                                        this.uploadData.splice(index,1);
                                                        this.$refs.uploadRef.removeFile(data.fileUploadName);
                                                }
                                        }
                                });
                        }).catch(()=>{})
                },
                saveProduct(){
                        this.$refs['ruleForm'].validate((valida)=>{
                                if(!valida){
                                        return
                                }
                                if(this.params.termsDetail==""){
                                        this.warn("请输入关键条款概述");
                                        return
                                }
                                if(!this.uploadData.length){
                                        this.warn("请上传进场函附件");
                                        return
                                }
                                if((new Date(this.params.contractEndDate).getTime()-new Date(this.params.contractBeginDate).getTime())<0){
                                        this.warn("合作结束日期不能小于合作开始日期");
                                        return
                                }
                                this.params.approachProductList=this.tableData;
                                this.params.id=Number(this.id);
                                this.$refs.uploadRef.submit().then((res)=>{//长传图片的操作
                                    for(let i=0;i<this.uploadData.length;i++){
                                        if(!this.uploadData[i].createTimeStr){
                                            for(let j=0;j<res.length;j++){
                                                if(this.uploadData[i].fileUploadName==res[j].split("cms/")[1]){
                                                    this.uploadData[i].fileAddress=res[j]
                                                }
                                            }
                                        }
                                    }
                                    this.params.contractFileList=this.uploadData;
                                    console.log(this.params.contractFileList);
                                    if(this.type=="edit"){
                                            console.log(this.params)
                                            this.axios.post(api.SAVEEDITDATA,this.params).then((res)=>{
                                                    if(res.data.code==200){
                                                            this.$alert("操作成功", '提示', {
                                                                    type: 'success ',
                                                                    confirmButtonText: '确定',
                                                                    callback: action => {
                                                                            this.$router.push({
                                                                                    path:"/enterletter"
                                                                            })
                                                                    }
                                                            });
                                                    }
                                            }).catch((error)=>{
                                                    console.log(error)
                                            })
                                    }else{
                                            this.axios.post(api.NEWINSERTENTER,this.params).then((res)=>{
                                                    if(res.data.code==200){
                                                            this.$alert("操作成功", '提示', {
                                                                    type: 'success ',
                                                                    confirmButtonText: '确定',
                                                                    callback: action => {
                                                                            this.$router.push({
                                                                                    path:"/enterletter"
                                                                            })
                                                                    }
                                                            });
                                                    }
                                            }).catch((error)=>{
                                                    console.log(error)
                                            })
                                    }
                                }).catch((error)=>{
                                    console.log(error)
                                })

                        })
                },
                faqishenpi(){
                    this.params.isfaqi=1;
                    this.saveProduct();
                },
                cancelSaveProduct(){
                        this.$router.push({
                                path:"/enterletter"
                        })
                },
                modifyName(name,index){
                        this.modifydialogVisible=true;
                        this.modifyindex=index;
                        this.textmodify=name.substring(name.lastIndexOf("."),0);
                },
                modifySave(){//确认修改文件名
                        if(this.textmodify==""){
                                this.warn("请输入文件名");
                                return
                        }
                        let originFilename=this.uploadData[this.modifyindex].fileName;
                        let Suffixname=originFilename.substring(originFilename.lastIndexOf(".")+1,originFilename.length);
                        this.uploadData[this.modifyindex].fileName=this.textmodify+"."+Suffixname;
                        this.modifydialogVisible=false;
                        this.textmodify="";
                        console.log(this.uploadData[this.modifyindex])
                },
                modifycancel(){//取消修改文件名
                        this.modifydialogVisible=false;
                        this.textmodify="";
                },
                downDoc(url,name){//下载doc文件
                    var a = document.createElement("a"); // 生成一个a元素
                    var event = new MouseEvent("click"); // 创建一个单击事件
                    a.download = name; // 设置图片名称
                    a.href = url; // 将生成的URL设置为a.href属性
                    a.dispatchEvent(event); // 触发a的单击事件
                        // window.open(this.uploadData[index].fileAddress, "_blank");
                },
                downPic(url,name,time){
                    if(time){
                       var image = new Image();
                        image.setAttribute("crossOrigin", "anonymous");
                        var _this = this;
                        image.onload = function () {
                            var canvas = document.createElement("canvas");
                            canvas.width = image.width;
                            canvas.height = image.height;
                            var context = canvas.getContext("2d");
                            context.drawImage(image, 0, 0, image.width, image.height);
                            var url = canvas.toDataURL("image/png"); //得到图片的base64编码数据
                            var a = document.createElement("a"); // 生成一个a元素
                            var event = new MouseEvent("click"); // 创建一个单击事件
                            a.download = name; // 设置图片名称
                            a.href = url; // 将生成的URL设置为a.href属性
                            a.dispatchEvent(event); // 触发a的单击事件
                        };
                        image.src = url; 
                    }else{
                        var base64ToBlob = function(code) {
                            let parts = code.split(';base64,');
                            let contentType = parts[0].split(':')[1];
                            let raw = window.atob(parts[1]);
                            let rawLength = raw.length;
                            let uInt8Array = new Uint8Array(rawLength);
                            for(let i = 0; i < rawLength; ++i) {
                                uInt8Array[i] = raw.charCodeAt(i);
                            }
                            return new Blob([uInt8Array], {
                                type: contentType
                            });
                        };
                        let aLink = document.createElement('a');
                        let blob = base64ToBlob(url); //new Blob([content]);
                        let evt = document.createEvent("HTMLEvents");
                        evt.initEvent("click", true, true); //initEvent 不加后两个参数在FF下会报错  事件类型，是否冒泡，是否阻止浏览器的默认行为
                        aLink.download = name;
                        aLink.href = URL.createObjectURL(blob);
                        aLink.click();
                    }
                    
                },
                getTimeString (timestamp) {
                        if (timestamp) {
                                const time = new Date(timestamp)
                                let dateStr = ''
                                const year = time.getFullYear()
                                const month = String(time.getMonth() + 1).length === 1 ? '0' + (time.getMonth() + 1) : (time.getMonth() + 1)
                                const day = String(time.getDate()).length === 1 ? '0' + time.getDate() : time.getDate()
                                dateStr = year + '-' + month + '-' + day
                                let timeStr = ''
                                const hours = time.getHours()
                                const hh = String(hours).length === 1 ? '0' + hours : hours
                                const minutes = time.getMinutes()
                                const mm = String(minutes).length === 1 ? '0' + minutes : minutes
                                const seconds = time.getSeconds()
                                const ss = String(seconds).length === 1 ? '0' + seconds : seconds
                                timeStr = `${hh}:${mm}:${ss}`
                                // timeStr = `${hh}:${mm}`
                                // return dateStr + ' ' + timeStr
                                return dateStr
                        } else {
                                return ''
                        }
                },
                getTimeString1 (timestamp) {
                        if (timestamp) {
                                const time = new Date(timestamp)
                                let dateStr = ''
                                const year = time.getFullYear()
                                const month = String(time.getMonth() + 1).length === 1 ? '0' + (time.getMonth() + 1) : (time.getMonth() + 1)
                                const day = String(time.getDate()).length === 1 ? '0' + time.getDate() : time.getDate()
                                dateStr = year + '-' + month + '-' + day
                                let timeStr = ''
                                const hours = time.getHours()
                                const hh = String(hours).length === 1 ? '0' + hours : hours
                                const minutes = time.getMinutes()
                                const mm = String(minutes).length === 1 ? '0' + minutes : minutes
                                const seconds = time.getSeconds()
                                const ss = String(seconds).length === 1 ? '0' + seconds : seconds
                                timeStr = `${hh}:${mm}:${ss}`
                                // timeStr = `${hh}:${mm}`
                                return dateStr + ' ' + timeStr
                                // return dateStr
                        } else {
                                return ''
                        }
                }
        },
        mounted(){
                if(this.type=="look" || this.type=="edit"){
                        this.initEnterData();
                }
        },
        components:{
                createCoop,
                uploadAll
        }
}
</script>
<style lang="stylus">
.s_body{
        .disUpload{
            margin-top: 10px;
            .el-upload-list{
                display: none;
            }
        }
}
</style>
<style lang="stylus" scope>
        .s_body{
                .especially{
                        .el-form-item{
                               width: 80%;
                        }
                        .el-form-item__content{
                                width: 80%;
                        }
                }
                .commonclass:before{
                        content: '*';
                        color: #f56c6c;
                        margin-right: 2px;
                }
                .tabs{
                    border-top: 1px solid #ccc;
                    border-left: 1px solid #ccc;
                    border-collapse: collapse;
                    width: 100%;
                    text-align: center;
                    td{
                        width: 20%;
                        border-bottom: 1px solid #ccc;
                        border-right: 1px solid #ccc;
                        padding: 15px 0;
                    }
                }
                .disUpload .el-upload-list{
                    display: none;
                }
        }
</style>
